﻿<div>
    <span>基本信息</span>
    @if (DocStatus != Utils.DocStatus.View && DocStatus != Utils.DocStatus.PCView)
    {
        <div style="float: right;">
            <PopConfirmButton Color="Color.Danger" IsDisabled="@IsDeleteDisabled" OnConfirm="(() => DeleteProduct(ProductModel))" ConfirmIcon="fa-solid fa-triangle-exclamation text-danger" ConfirmButtonColor="Color.Danger" Content="@deleteMessage">删除商品</PopConfirmButton>
        </div>
    }
</div>
<ValidateForm Model="@ProductModel" ValidateAllProperties="true" style="margin-top: 1rem;" OnInvalidSubmit="OnInvalidSubmit" OnValidSubmit="OnValidSubmit">
    <GroupBox>
        <EditorForm TModel="Product" Model="ProductModel" AutoGenerateAllItem="false" ItemsPerRow="4">
            <FieldItems>
                <EditorItem @bind-Field="@context.Name" Readonly="@IsFieldReadOnly" />
                <EditorItem @bind-Field="@context.PId" Readonly="@IsFieldReadOnly" />
                <EditorItem @bind-Field="@context.UPC" Readonly="@IsFieldReadOnly" />
                <EditorItem @bind-Field="@context.Specification" Readonly="@IsFieldReadOnly" />
                <EditorItem @bind-Field="@context.Brand" Readonly="@IsFieldReadOnly" />
                <EditorItem @bind-Field="@context.SectionId" Readonly="@IsFieldReadOnly">
                    <EditTemplate Context="value">
                        <div class="col-12 col-sm-6 col-md-3">
                            <BootstrapInput DisplayText="商品分类" ShowLabel="true" Value="@ProductService.GetProductDepartment(value.SectionId).Description" IsDisabled="@IsFieldReadOnly" />
                        </div>
                    </EditTemplate>
                </EditorItem>
                <EditorItem @bind-Field="@context.OriginPlace" Readonly="@IsFieldReadOnly" />
                <EditorItem @bind-Field="@context.CreatedOn" Readonly="true" />
                <EditorItem @bind-Field="@context.CreatedBy" Readonly="true" />
                <EditorItem @bind-Field="@context.LastModifiedOn" Readonly="true" />
                <EditorItem @bind-Field="@context.LastModifiedBy" Readonly="true" />
            </FieldItems>
        </EditorForm>
    </GroupBox>

    <Row ItemsPerRow="ItemsPerRow.Three" style="margin-top: 1rem;">
        <Row RowType="RowType.Inline">
            <span>关联供应商</span>
            <Row ItemsPerRow="ItemsPerRow.Two" RowType="RowType.Normal">
                <Select Color="Color.Primary" Items="SupplierList" ShowSearch="true" ShowLabel="false" @bind-Value="SupplierId" PlaceHolder="请选择关联供应商" OnSelectedItemChanged="OnParameterChange" />
                <Button Text="查看供应商" OnClick="GetSupplier" IsDisabled="@string.IsNullOrEmpty(SupplierId)" />
            </Row>
        </Row>
    </Row>
    <GroupBox style="margin-top: 1rem;">
        <Row ItemsPerRow="ItemsPerRow.Four" RowType="RowType.Normal">
            <BootstrapInput @bind-Value="@SupplierName" Readonly="true" DisplayText="供应商名称" ShowLabel="true"></BootstrapInput>
            <BootstrapInput @bind-Value="@SupplierContact" Readonly="true" DisplayText="联系人" ShowLabel="true"></BootstrapInput>
            <Select @bind-Value="@SupplierRegion" IsDisabled="true" DisplayText="区域" ShowLabel="true"></Select>
            <DateTimePicker @bind-Value="@SupplierCreatedOn" IsDisabled="true" DisplayText="创建时间" ShowLabel="true"></DateTimePicker>
            <BootstrapInput @bind-Value="@SupplierSId" Readonly="true" DisplayText="供应商编号" ShowLabel="true"></BootstrapInput>
            <BootstrapInput @bind-Value="@SupplierContactNumber" Readonly="true" DisplayText="联系电话" ShowLabel="true"></BootstrapInput>
            <BootstrapInput @bind-Value="@SupplierCreatedBy" Readonly="true" DisplayText="创建者" ShowLabel="true"></BootstrapInput>
            <DateTimePicker @bind-Value="@SupplierLastModifiedOn" IsDisabled="true" DisplayText="最近更新时间" ShowLabel="true"></DateTimePicker>
        </Row>
    </GroupBox>
    <div style="margin-top: 1.5rem;">
        <span>商品证照信息</span>
        <span style="color: red" hidden="@IsFieldReadOnly">上传商品证照信息前请先创建商品信息</span>
        @if (DocStatus == Utils.DocStatus.View)
        {
            <Table style="margin-top: 3rem;" TItem="Core.Models.ProductLicense" OnQueryAsync="OnLicenseQueryAsync"
                   IsStriped="true" IsBordered="true" SelectedRows="@SelectedLicense" SelectedRowsChanged="@SelectChanged"
                   ShowSkeleton="true" ShowEmpty="true" ShowSearch="true">
                <TableColumns>
                    <TableColumn @bind-Field="@context.Type" Width="100">
                        <Template Context="value">
                            <Tag Color="Color.Primary">@GetLicenseTypeName(value.Value)</Tag>
                        </Template>
                    </TableColumn>
                    <TableColumn @bind-Field="@context.LId" Width="100" />
                    <TableColumn @bind-Field="@context.ValidFromDate" Width="100" FormatString="yyyy年MM月dd日" />
                    <TableColumn @bind-Field="@context.ValidToDate" Width="100" FormatString="yyyy年MM月dd日" />
                    <TableColumn @bind-Field="@context.CreatedOn" Width="100" />
                    <TableColumn @bind-Field="@context.ValidToDate" Width="100" Text="状态">
                        <Template Context="value">
                            @*@if (DateTime.Compare(DateTime.Now, value.Value) > 0)*@
                            @if (!value.Row.IsPublish)
                            {
                                <Tag Color="Color.Dark">未生效</Tag>
                            }
                            else if (DateTime.Now > value.Value)
                            {
                                <Tag Color="Color.Danger">已过期</Tag>
                            }
                            else if (DateTime.Now <= value.Value)
                            {
                                <Tag Color="Color.Success">生效中</Tag>
                            }
                            else if (value.Value == null)
                            {
                                <Tag Color="Color.Success">长期有效</Tag>
                            }
                        </Template>
                    </TableColumn>
                    <TableColumn @bind-Field="@context.Id" Text="操作">
                        <Template Context="value">
                            <Button Text="查看" OnClick="@(() => View(value.Row))" />
                        </Template>
                    </TableColumn>
                    @*<TableColumn @bind-Field="@context.Attachment.URL" Width="100" />*@
                </TableColumns>
            </Table>
            <div class="form-footer mt-3">
                <button type="button" class="btn btn-secondary" @onclick="@(e => OnClose?.Invoke())">
                    <i class="fa-solid fa-xmark"></i>
                    <span>关闭</span>
                </button>
            </div>
        }
        else if (DocStatus == Utils.DocStatus.PCView)
        {
            <Table style="margin-top: 3rem;" TItem="Core.Models.ProductLicense" OnQueryAsync="OnLicenseQueryAsync"
                   IsStriped="true" IsBordered="true" OnDoubleClickRowCallback="@View" SelectedRows="@SelectedLicense" SelectedRowsChanged="@SelectChanged"
                   ShowSkeleton="true" ShowEmpty="true" ShowSearch="true">
                <TableColumns>
                    <TableColumn @bind-Field="@context.Type" Width="100">
                        <Template Context="value">
                            <Tag Color="Color.Primary">@GetLicenseTypeName(value.Value)</Tag>
                        </Template>
                    </TableColumn>
                    <TableColumn @bind-Field="@context.LId" Width="100" />
                    <TableColumn @bind-Field="@context.ValidFromDate" Width="100" FormatString="yyyy年MM月dd日" />
                    <TableColumn @bind-Field="@context.ValidToDate" Width="100" FormatString="yyyy年MM月dd日" />
                    <TableColumn @bind-Field="@context.CreatedOn" Width="100" />
                    <TableColumn @bind-Field="@context.ValidToDate" Width="100" Text="状态">
                        <Template Context="value">
                            @*@if (DateTime.Compare(DateTime.Now, value.Value) > 0)*@
                            @if (!value.Row.IsPublish)
                            {
                                <Tag Color="Color.Dark">未生效</Tag>
                            }
                            else if (DateTime.Now > value.Value)
                            {
                                <Tag Color="Color.Danger">已过期</Tag>
                            }
                            else if (DateTime.Now <= value.Value)
                            {
                                <Tag Color="Color.Success">生效中</Tag>
                            }
                            else if (value.Value == null)
                            {
                                <Tag Color="Color.Success">长期有效</Tag>
                            }
                        </Template>
                    </TableColumn>
                </TableColumns>
            </Table>
            <div class="form-footer mt-3">
                <button type="button" class="btn btn-secondary" @onclick="@(e => OnClose?.Invoke())">
                    <i class="fa-solid fa-xmark"></i>
                    <span>关闭</span>
                </button>
            </div>
        }
        else
        {
            <div style="float: right;">
                <Button Text="添加证照" OnClick="Add" IsDisabled="IsButtonDisabled" />
                <Button Text="编辑证照" OnClick="@EditBtn" IsDisabled="@(SelectedLicense.Count != 1)" />
                <PopConfirmButton Color="Color.Danger" IsDisabled="@(SelectedLicense.Count == 0 || IsDeleteDisabled)" OnConfirm="(() => Delete(SelectedLicense))" ConfirmIcon="fa-solid fa-triangle-exclamation text-danger" ConfirmButtonColor="Color.Danger" Content="确定删除选中的记录吗？">删除证照</PopConfirmButton>
            </div>
            <Table style="margin-top: 3rem;" TItem="Core.Models.ProductLicense" OnQueryAsync="OnLicenseQueryAsync"
                   IsStriped="true" IsBordered="true" IsMultipleSelect="true" OnDoubleClickRowCallback="@Edit" SelectedRows="@SelectedLicense" SelectedRowsChanged="@SelectChanged"
                   ShowSkeleton="true" ShowEmpty="true" ShowSearch="true">
                <TableColumns>
                    <TableColumn @bind-Field="@context.Type" Width="100">
                        <Template Context="value">
                            <Tag Color="Color.Primary">@GetLicenseTypeName(value.Value)</Tag>
                        </Template>
                    </TableColumn>
                    <TableColumn @bind-Field="@context.LId" Width="100" />
                    <TableColumn @bind-Field="@context.ValidFromDate" Width="100" FormatString="yyyy年MM月dd日" />
                    <TableColumn @bind-Field="@context.ValidToDate" Width="100" FormatString="yyyy年MM月dd日" />
                    <TableColumn @bind-Field="@context.CreatedOn" Width="100" />
                    <TableColumn @bind-Field="@context.ValidToDate" Width="100" Text="状态">
                        <Template Context="value">
                            @*@if (DateTime.Compare(DateTime.Now, value.Value) > 0)*@
                            @if (!value.Row.IsPublish)
                            {
                                <Tag Color="Color.Dark">未生效</Tag>
                            }
                            else if (DateTime.Now > value.Value)
                            {
                                <Tag Color="Color.Danger">已过期</Tag>
                            }
                            else if (DateTime.Now <= value.Value)
                            {
                                <Tag Color="Color.Success">生效中</Tag>
                            }
                            else if (value.Value == null)
                            {
                                <Tag Color="Color.Success">长期有效</Tag>
                            }
                        </Template>
                    </TableColumn>
                    @*<TableColumn @bind-Field="@context.Attachment.URL" Width="100" />*@
                </TableColumns>
            </Table>
            <div class="form-footer mt-3">
                <button type="button" class="btn btn-secondary" @onclick="@(e => OnClose?.Invoke())">
                    <i class="fa-solid fa-xmark"></i>
                    <span>关闭</span>
                </button>
                <Button Color="Color.Primary" ButtonType="ButtonType.Submit" Icon="fa-solid fa-floppy-disk" Text="保存" IsDisabled="@IsSaveDisabled" />
            </div>
        }

        @*<ListView style="margin-top: 1.5rem;" TItem="SupplierLicense" Items="@SupplierModel.SupplierLicenses">
            <BodyTemplate>
                <Card>
                    <BodyTemplate>
                        <img src="@context.Attachment.URL" />
                        <div>@context.Tag.Value</div>
                    </BodyTemplate>
                </Card>
            </BodyTemplate>
        </ListView>*@
        @*<div class="col-12 col-sm-6">
            <span>上传证照</span>
            <CardUpload Accept="image/*" DefaultFileList="@Base64FormatFile" IsSingle="true" TValue="string" ShowProgress="true" ShowDeleteButton="true" ShowDownloadButton="true">上传证照</CardUpload>
            <span>其他附件</span>
            <ButtonUpload TValue="string" IsMultiple="true" ShowDownloadButton="true" DefaultFileList="@OtherFileList"></ButtonUpload>
        </div>*@
    </div>
</ValidateForm>